﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Sms;

namespace EasyAbp.Abp.PhoneNumberLogin.Provider.Aliyun.ConsoleTests
{
   public class ConsoleTestAppHostService : IHostedService
    {
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            using (var application = AbpApplicationFactory.Create<AliyunConsoleTestModule>())
            {
                application.Initialize();

                const string code = "123456";
                string phone = "";

                var smsSender = application.ServiceProvider.GetRequiredService<ISmsSender>();

                var smsMessage = new SmsMessage(phone, "placeholder");

                smsMessage.Properties.Add(PhoneNumberLoginProviderAliyunConsts.SignName, "");
                smsMessage.Properties.Add(PhoneNumberLoginProviderAliyunConsts.TemplateCode, "");
                smsMessage.Properties.Add(PhoneNumberLoginProviderAliyunConsts.TemplateParam, new { code = code });

                await smsSender.SendAsync(smsMessage);

                application.Shutdown();
            }
        }

        public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
    }
}